package com.spring.security.study.security_test.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName : AccessDenied
 * @Author : lby
 * @Date: 2021/1/25 15:04
 * @Description : 无访问权限处理
 */
@Slf4j
@Component
public class UserAccessDeniedHandler implements AccessDeniedHandler {

    /**
     * 重写方法，处理当用户没有权限访问时
     * @param request
     * @param response
     * @param e
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        Map<String,String > map=new HashMap<String, String>();
        map.put("code","403");
        map.put("msg","Access Denied");
        log.info("数据:{}",map);

    }
}
